package com.spddr.pmos.cxf.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.spddr.pmos.cxf.JaxrsCustomerCredit;
import com.spddr.pmos.jpa.CustomerCredit;
import com.spddr.pmos.jpa.CustomerEvalId;
import com.spddr.pmos.repos.CustomerCreditRepos;

@Service
public class JaxrsCustomerCreditImpl implements JaxrsCustomerCredit {
	@Autowired
	private CustomerCreditRepos repository;

	@Override
	public JpaRepository<CustomerCredit, CustomerEvalId> getRepository() {
		return repository;
	}

	@Override
	public List<CustomerCredit> findByCustomer(long customer) {
		return repository.findByIdCustomer(customer);
	}

	@Override
	public void saveByCustomer(long customer, List<CustomerCredit> entities) {
		repository.save(entities.stream()
				.peek(x -> x.getId()
						.setCustomer(customer))
				.collect(Collectors.toList()));
	}

	@Override
	public void deleteByCustomer(long customer) {
	}
}
